package com.baor.web.controller.order;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.baor.common.annotation.Log;
import com.baor.common.core.controller.BaseController;
import com.baor.common.core.domain.AjaxResult;
import com.baor.common.enums.BusinessType;
import com.baor.order.domain.TReviews;
import com.baor.order.service.ITReviewsService;
import com.baor.common.utils.poi.ExcelUtil;
import com.baor.common.core.page.TableDataInfo;

/**
 * 商品评价Controller
 * 
 * @author ruoyi
 * @date 2025-07-18
 */
@RestController
@RequestMapping("/order/reviews")
public class TReviewsController extends BaseController
{
    @Autowired
    private ITReviewsService tReviewsService;

    /**
     * 查询商品评价列表
     */
    @GetMapping("/list")
    public TableDataInfo list(TReviews tReviews)
    {
        startPage();
        List<TReviews> list = tReviewsService.selectTReviewsList(tReviews);
        return getDataTable(list);
    }

    /**
     * 导出商品评价列表
     */
    @PreAuthorize("@ss.hasPermi('order:reviews:export')")
    @Log(title = "商品评价", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TReviews tReviews)
    {
        List<TReviews> list = tReviewsService.selectTReviewsList(tReviews);
        ExcelUtil<TReviews> util = new ExcelUtil<TReviews>(TReviews.class);
        util.exportExcel(response, list, "商品评价数据");
    }

    /**
     * 获取商品评价详细信息
     */
    @PreAuthorize("@ss.hasPermi('order:reviews:query')")
    @GetMapping(value = "/{reviewsId}")
    public AjaxResult getInfo(@PathVariable("reviewsId") Long reviewsId)
    {
        return success(tReviewsService.selectTReviewsByReviewsId(reviewsId));
    }

    /**
     * 新增商品评价
     */
    @PreAuthorize("@ss.hasPermi('order:reviews:add')")
    @Log(title = "商品评价", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TReviews tReviews)
    {
        return toAjax(tReviewsService.insertTReviews(tReviews));
    }
    @PostMapping("/reply")
    public AjaxResult reply(@RequestBody TReviews tReviews)
        {
        return toAjax(tReviewsService.insertTReviewsReply(tReviews));
    }
    @PostMapping("/top")
    public AjaxResult top(@RequestBody TReviews tReviews)
        {
        return toAjax(tReviewsService.updateTReviewsTop(tReviews));
    }

    @PostMapping("/cancelTop")
    public AjaxResult cancelTop(@RequestBody TReviews tReviews)
        {
        return toAjax(tReviewsService.updateTReviewsCancelTop(tReviews));
    }
    @PostMapping("/deleteTReviews")
    public AjaxResult deleteTReviews(@RequestBody TReviews tReviews)
        {
        return toAjax(tReviewsService.deleteTReviews(tReviews));
    }

    /**
     * 修改商品评价
     */
    @PreAuthorize("@ss.hasPermi('order:reviews:edit')")
    @Log(title = "商品评价", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TReviews tReviews)
    {
        return toAjax(tReviewsService.updateTReviews(tReviews));
    }

    /**
     * 删除商品评价
     */
    @PreAuthorize("@ss.hasPermi('order:reviews:remove')")
    @Log(title = "商品评价", businessType = BusinessType.DELETE)
	@DeleteMapping("/{reviewsIds}")
    public AjaxResult remove(@PathVariable Long[] reviewsIds)
    {
        return toAjax(tReviewsService.deleteTReviewsByReviewsIds(reviewsIds));
    }
}
